home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
VideoToolbox 96.06.15
/
VideoToolboxSources
/
IsFileSharingOn.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-06-24
|
4KB
|
119 lines
/*
IsFileSharingOn.c
if(IsFileSharingOn()) ...
Checks for running AppleShare server or File Sharing Extension. Returns 1 if either is running,
or 0 if neither is running.
The AppleShare part is based on information in gestalt-selectors-29.etx
The FileShare part assumes that the Type and Creator of the File Sharing Extension will never
change.
It would be nice to know if there is an Apple-approved way of determining the same things.
error=KillFileSharing();
Kills the File Sharing Extension process (Apple's "personal file share" built-in to System 7),
if it's running. This won't affect AppleShare server software (which you buy separately).
SEE ALSO:
ftp://sumex-aim.stanford.edu/info-mac/dev/info/gestalt-selectors-29.hqx
HISTORY:
6/21/95 dgp wrote it, after discussing it with David Brainard.
6/23/95 dhb removed main(). Added KillFileSharing().
6/24/95 dgp modified KillFileSharing to do nothing if the FInder isn't running.
Check gestaltAppleEventsPresent.
*/
#include "VideoToolbox.h"
#include <Processes.h>
#include <AppleEvents.h>
enum{
gestaltASFileServerAttr= 'hgfd',
gestaltASFileServerPresent=0
};
Boolean IsFileSharingOn(void)
{
ProcessSerialNumber psn={kNoProcess,kNoProcess};
ProcessInfoRec infoRec;
Str31 processName;
FSSpec procSpec;
int error;
long value;
// Is the AppleShare File Server running?
error=Gestalt(gestaltASFileServerAttr,&value);
if(!error && value&(1L<<gestaltASFileServerPresent))return 1; // Yes
// Check all processes running on this machine.
while(1){
error=GetNextProcess(&psn);
if(error)return 0; // No more processes to check: go home.
/* Is this process the File Sharing Extension? */
infoRec.processInfoLength=sizeof(ProcessInfoRec);
infoRec.processName=processName;
infoRec.processAppSpec=&procSpec;
GetProcessInformation(&psn,&infoRec);
if(infoRec.processSignature=='hhgg' && infoRec.processType=='INIT')return 1; // Yes.
}
}
OSErr KillFileSharing(void)
{
ProcessSerialNumber psn={kNoProcess,kNoProcess},fileSharingPSN;
ProcessInfoRec infoRec;
Str31 processName;
FSSpec procSpec;
AppleEvent event;
AEDesc address;
int error;
Boolean foundFinder=0,foundFileSharing=0;
long value;
error=Gestalt(gestaltAppleEventsAttr,&value);
if(error || !(value&(1<<gestaltAppleEventsPresent)))return 1;
// Check all processes running on this machine.
while(1){
error=GetNextProcess(&psn);
if(error)break; // No more processes to check.
infoRec.processInfoLength=sizeof(ProcessInfoRec);
infoRec.processName=processName;
infoRec.processAppSpec=&procSpec;
GetProcessInformation(&psn,&infoRec);
/* Is this process the Finder? */
if(infoRec.processSignature=='MACS' && infoRec.processType=='FNDR')
foundFinder=1;
/* Is this process the File Sharing Extension? */
if(infoRec.processSignature=='hhgg' && infoRec.processType=='INIT'){
fileSharingPSN=psn;
foundFileSharing=1;
}
}
if(foundFinder && foundFileSharing){
// According to a comment by C.K.Haun in KillEveryoneButMe.c, "FileSharing must
// be killed before the Finder". I'm not clear on why. Is it bad to leave FileSharing
// running without a Finder? Or is it bad to kill FileSharing when there is no Finder?
// These different interpretations have opposite implications for what to do if we
// discover that FileSharing is running and the Finder isn't.
// Not knowing the answer, this code conservatively only tries to kill FileSharing if
// the Finder IS running.
error=AECreateDesc(typeProcessSerialNumber,(Ptr)&fileSharingPSN,sizeof(psn),&address);
if(!error){
error=AECreateAppleEvent(kCoreEventClass,kAEQuitApplication,&address
,kAutoGenerateReturnID,kAnyTransactionID,&event);
AEDisposeDesc(&address);
if(!error){
AESend(&event,NULL,kAENoReply+kAEAlwaysInteract+kAECanSwitchLayer
,kAENormalPriority,kAEDefaultTimeout,NULL,NULL);
AEDisposeDesc(&event);
}
}
}
return error;
}